package com.bw.module_cinema.search

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bw.module_cinema.databinding.ItemSearchVideoBinding
import com.bw.module_cinema.search.entity.SearchVideoEntity

class SearchResultAdapter : RecyclerView.Adapter<SearchResultAdapter.SearchViewHolder>() {

    companion object {
        private const val TAG = "SearchResultAdapter"
    }

    private val list = ArrayList<SearchVideoEntity>()

    fun setData(mList: List<SearchVideoEntity>){
        list.clear()
        list.addAll(mList)
        notifyDataSetChanged()
    }

    class SearchViewHolder(
        val binding : ItemSearchVideoBinding
    ) :RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchViewHolder {
        val binding = ItemSearchVideoBinding.inflate(LayoutInflater.from(parent.context),parent,false)
        return SearchViewHolder(binding)
    }

    override fun getItemCount(): Int {
        return list.size
    }

    override fun onBindViewHolder(holder: SearchViewHolder, position: Int) {
        val item = list[position]
        holder.binding.search = item
    }

}


